﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace WPFDBBrowser.Framework
{
    internal class ServiceProvider : IServiceProvider
    {
        private Dictionary<Type, object> _registeredServices = new Dictionary<Type, object>();

        #region IServiceProvider Members

        public object GetService(Type serviceType)
        {
            if (this._registeredServices.ContainsKey(serviceType))
                return this._registeredServices[serviceType];
            throw new ArgumentOutOfRangeException("serviceType",
                string.Format("DBBrowser.Framework.ServiceProvider: Unknown service type {0}.", serviceType));
        }

        #endregion

        public void AddService<TService>(TService service)
        {
            Type serviceType = service.GetType();
            if (this._registeredServices.ContainsKey(serviceType))
                this._registeredServices[serviceType] = service;
            else
                this._registeredServices.Add(serviceType, service);
        }
    }
}
